/*!
 * @file rt_sbus.h
 * @brief Communication with RC controller receiver
 */

#ifndef _rt_sbus
#define _rt_sbus

#include <stdint.h>

#define RC_ELRS

enum TaranisSwitchState
{
    SWITCH_UP     = 0,
    SWITCH_MIDDLE = 1,
    SWITCH_DOWN   = 2,
};

struct Taranis_X7_data
{
    TaranisSwitchState left_upper_switch, left_lower_left_switch, left_lower_right_switch,
            right_upper_switch, right_lower_left_switch, right_lower_right_switch;

    float left_stick[2];
    float right_stick[2];
    float knobs[2];
};

void unpack_sbus_data(uint8_t sbus_data[], uint16_t* channels);
int  read_sbus_data(int port, uint8_t* sbus_data);
int  read_sbus_channel(int channel);
int  receive_sbus(int port);
int  init_sbus(int is_simulator);
void update_taranis_x7(Taranis_X7_data* data);

// ELRS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// enum ELRS_SwitchStateBool
// {
//     ELRS_BOOL_UP   = 0,
//     ELRS_BOOL_DOWN = 1,
// };

// enum ELRS_SwitchStateTri
// {
//     ELRS_TRI_UP     = 0,
//     ELRS_TRI_MIDDLE = 1,
//     ELRS_TRI_DOWN   = 2,
// };

enum ELRS_SwitchState
{
    ELRS_SWITCH_DOWN   = 0,
    ELRS_SWITCH_MIDDLE = 1,
    ELRS_SWITCH_UP     = 2,
};

struct ELRS_data
{
    // ELRS_SwitchStateBool SA, SD;
    // ELRS_SwitchStateTri  SB, SC;
    ELRS_SwitchState SA, SB, SC, SD;
    float            left_stick_x, left_stick_y, right_stick_x, right_stick_y;
};

void unpack_elrs_data(uint8_t data[], uint16_t* channels);
int  read_elrs_data(int port, uint8_t* data);
int  receive_elrs(int port);
int  init_elrs(int is_simulator);
void update_elrs(ELRS_data* data);

#endif
